<?php
/**
 * [LupMisNotAllowedSync]
 * 本代码为系统自动生成代码，请根据自己业务进行修改;
 * 生成时间 2022-02-15 20:59:20;
 * 版权所有 2020-2022 lizhongwen，并保留所有权利;
 * 说明: 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；不允许对程序代码以任何形式任何目的的再发布;
 * 作者: 中文Lee;
 * 作者主页: http://www.lizhongwen.com;
 * 邮箱: 360811363@qq.com;
 * QQ: 360811363;
 */

namespace application\component;

use application\core\Lib;
use modules\sys\mapper\FieldMapper;
use modules\sys\mapper\TableMapper;

class BuildCodeComponent
{
    public function syncCode($tableName, $pages): array
    {
        $pagesArray = explode(",", $pages);
        $ret = $this->buildCode($tableName);
        $prefix = $ret['prefix'];
        $filter = $ret['filter'];
        $htmlDir = $ret['html_dir'];
        $className = $ret['class_name'];
        $controllerCode = $ret['controller'];
        $serviceCode = $ret['service'];
        $serviceImplCode = $ret['service_impl'];
        $mapperCode = $ret['mapper'];
        $xmlCode = $ret['xml'];
        $indexCode = $ret['index'];
        $addCode = $ret['add'];
        $editCode = $ret['edit'];
        if ($prefix == 'sys' || $prefix == "sys_") {
            $msgArr[] = "<span style='color:red'>系统功能不允许同步</span>";
            return $msgArr;
        }
        $filterPath = APP_PATH . "application/filter/" . ucfirst($prefix) . "Filter.php";
        if (!file_exists($filterPath)) {
            file_put_contents($filterPath, $filter);
        }
        $htmlPath = APP_PATH . "public/lup-mis/pages/" . $prefix . "/" . $htmlDir . "/";
        $xmlPath = APP_PATH . "resources/mapper/" . $prefix . "/";
        $modulesPath = APP_PATH . "modules/" . $prefix . "/";
        $backupModulesPath = APP_PATH . "resources/data/backup/modules/" . $prefix . "/";
        $backupXmlPath = APP_PATH . "resources/data/backup/resources/mapper/" . $prefix . "/";
        $backupHtmlPath = APP_PATH . "resources/data/backup/public/lup-mis/pages/" . $prefix . "/" . $htmlDir . "/";

        $controllerFile = $modulesPath . "controller/" . $className . "Controller.php";
        $backupControllerFile = $backupModulesPath . "controller/" . $className . "Controller.php";

        $serviceFile = $modulesPath . "service/" . $className . "Service.php";
        $backupServiceFile= $backupModulesPath . "service/" . $className . "Service.php";

        $serviceImplFile = $modulesPath . "service/impl/" . $className . "ServiceImpl.php";
        $backupServiceFileImpl = $backupModulesPath . "service/impl/" . $className . "ServiceImpl.php";

        $mapperFile = $modulesPath . "mapper/" . $className . "Mapper.php";
        $backupMapperFile= $backupModulesPath . "mapper/" . $className . "Mapper.php";

        $xmlFile = $xmlPath . $tableName . ".xml";
        $backupXmlFile = $backupXmlPath . $tableName . ".xml";

        $indexFile = $htmlPath . "index.html";
        $backupIndexFile = $backupHtmlPath . "index.html";

        $addFile = $htmlPath . "add.html";
        $backupAddFile = $backupHtmlPath . "add.html";

        $editFile = $htmlPath . "edit.html";
        $backupEditFile = $backupHtmlPath . "edit.html";

        $tag = "[LupMisAllowedSync-lock]";
        $backName = date("YmdHis");
        $msgArr = [];
        //写入Controller start
        if (in_array("Controller.php", $pagesArray)) {
            if (file_exists($controllerFile)) {
                if (strpos(file_get_contents($controllerFile), $tag)) {
                    $msgArr[] = "<span style='color: red'>Controller写入失败，页面已经锁定" . $tag . "</span>";
                } else {
                    if (!file_exists($modulesPath . "controller/") || !is_writable($modulesPath . "controller/")) {
                        mkdir($modulesPath . "controller/", 0755, true);
                    }
                    //先备份
                    if (!file_exists($backupModulesPath . "controller/") || !is_writable($backupModulesPath . "controller/")) {
                        mkdir($backupModulesPath . "controller/", 0755, true);
                    }
                    file_put_contents($backupControllerFile.".".$backName, file_get_contents($controllerFile));

                    file_put_contents($controllerFile, $controllerCode);
                    $msgArr[] = "<span style='color: green'>Controller写入成功</span>";
                }
            } else {
                if (!file_exists($modulesPath . "controller/") || !is_writable($modulesPath . "controller/")) {
                    mkdir($modulesPath . "controller/", 0755, true);
                }
                file_put_contents($controllerFile, $controllerCode);
                $msgArr[] = "<span style='color: green'>Controller写入成功</span>";
            }
        } else {
            $msgArr[] = "<span style='color:#999999'>未选择Controller</span>";
        }
        //写入Controller end

        //写入Service start
        if (in_array("Service.php", $pagesArray)) {
            if (file_exists($serviceFile)) {
                if (strpos(file_get_contents($serviceFile), $tag)) {
                    $msgArr[] = "<span style='color: red'>Service写入失败，页面已经锁定" . $tag . "</span>";
                } else {
                    if (!file_exists($modulesPath . "service/") || !is_writable($modulesPath . "service/")) {
                        mkdir($modulesPath . "service/", 0755, true);
                    }
                    //先备份
                    if (!file_exists($backupModulesPath . "service/") || !is_writable($backupModulesPath . "service/")) {
                        mkdir($backupModulesPath . "service/", 0755, true);
                    }
                    file_put_contents($backupServiceFile.".".$backName, file_get_contents($serviceFile));

                    file_put_contents($serviceFile, $serviceCode);
                    $msgArr[] = "<span style='color: green'>Service写入成功</span>";
                }
            } else {
                if (!file_exists($modulesPath . "service/") || !is_writable($modulesPath . "service/")) {
                    mkdir($modulesPath . "service/", 0755, true);
                }
                file_put_contents($serviceFile, $serviceCode);
                $msgArr[] = "<span style='color: green'>Service写入成功</span>";
            }
        } else {
            $msgArr[] = "<span style='color:#999999'>未选择Service</span>";
        }
        //写入Service end

        //写入ServiceImpl start
        if (in_array("ServiceImpl.php", $pagesArray)) {
            if (file_exists($serviceImplFile)) {
                if (strpos(file_get_contents($serviceImplFile), $tag)) {
                    $msgArr[] = "<span style='color: red'>ServiceImpl写入失败，页面已经锁定" . $tag . "</span>";
                } else {
                    if (!file_exists($modulesPath . "service/impl/") || !is_writable($modulesPath . "service/impl/")) {
                        mkdir($modulesPath . "service/impl/", 0755, true);
                    }
                    //先备份
                    if (!file_exists($backupModulesPath . "service/impl/") || !is_writable($backupModulesPath . "service/impl/")) {
                        mkdir($backupModulesPath . "service/impl/", 0755, true);
                    }
                    file_put_contents($backupServiceFileImpl.".".$backName, file_get_contents($serviceImplFile));


                    file_put_contents($serviceImplFile, $serviceImplCode);
                    $msgArr[] = "<span style='color: green'>ServiceImpl写入成功</span>";
                }
            } else {
                if (!file_exists($modulesPath . "service/impl/") || !is_writable($modulesPath . "service/impl/")) {
                    mkdir($modulesPath . "service/impl/", 0755, true);
                }
                file_put_contents($serviceImplFile, $serviceImplCode);
                $msgArr[] = "<span style='color: green'>ServiceImpl写入成功</span>";
            }
        } else {
            $msgArr[] = "<span style='color:#999999'>未选择ServiceImpl</span>";
        }
        //写入ServiceImpl end

        //写入Mapper start
        if (in_array("Mapper.php", $pagesArray)) {
            if (file_exists($mapperFile)) {
                if (strpos(file_get_contents($mapperFile), $tag)) {
                    $msgArr[] = "<span style='color: red'>Mapper写入失败，页面已经锁定" . $tag . "</span>";
                } else {
                    if (!file_exists($modulesPath . "mapper/") || !is_writable($modulesPath . "mapper/")) {
                        mkdir($modulesPath . "mapper/", 0755, true);
                    }
                    //先备份
                    if (!file_exists($backupModulesPath . "mapper/") || !is_writable($backupModulesPath . "mapper/")) {
                        mkdir($backupModulesPath . "mapper/", 0755, true);
                    }
                    file_put_contents($backupMapperFile.".".$backName, file_get_contents($mapperFile));


                    file_put_contents($mapperFile, $mapperCode);
                    $msgArr[] = "<span style='color: green'>Mapper写入成功</span>";
                }
            } else {
                if (!file_exists($modulesPath . "mapper/") || !is_writable($modulesPath . "mapper/")) {
                    mkdir($modulesPath . "mapper/", 0755, true);
                }
                file_put_contents($mapperFile, $mapperCode);
                $msgArr[] = "<span style='color: green'>Mapper写入成功</span>";
            }
        } else {
            $msgArr[] = "<span style='color:#999999'>未选择Mapper</span>";
        }
        //写入Mapper end

        //写入xml start
        if (in_array("Mapper.xml", $pagesArray)) {
            if (file_exists($xmlFile)) {
                if (strpos(file_get_contents($xmlFile), $tag)) {
                    $msgArr[] = "<span style='color: red'>xml写入失败，页面已经锁定" . $tag . "</span>";
                } else {
                    if (!file_exists($xmlPath) || !is_writable($xmlPath)) {
                        mkdir($xmlPath, 0755, true);
                    }
                    //先备份
                    if (!file_exists($backupXmlPath) || !is_writable($backupXmlPath)) {
                        mkdir($backupXmlPath, 0755, true);
                    }
                    file_put_contents($backupXmlFile.".".$backName, file_get_contents($xmlFile));

                    file_put_contents($xmlFile, $xmlCode);
                    $msgArr[] = "<span style='color: green'>xml写入成功</span>";
                }
            } else {
                if (!file_exists($xmlPath) || !is_writable($xmlPath)) {
                    mkdir($xmlPath, 0755, true);
                }
                file_put_contents($xmlFile, $xmlCode);
                $msgArr[] = "<span style='color: green'>xml写入成功</span>";
            }
        } else {
            $msgArr[] = "<span style='color:#999999'>未选择xml</span>";
        }
        //写入xml end


        //写入index start
        if (in_array("index.html", $pagesArray)) {
            if (file_exists($indexFile)) {
                if (strpos(file_get_contents($indexFile), $tag)) {
                    $msgArr[] = "<span style='color: red'>index.html写入失败，页面已经锁定" . $tag . "</span>";
                } else {
                    if (!file_exists($htmlPath) || !is_writable($htmlPath)) {
                        mkdir($htmlPath, 0755, true);
                    }
                    //先备份
                    if (!file_exists($backupHtmlPath) || !is_writable($backupHtmlPath)) {
                        mkdir($backupHtmlPath, 0755, true);
                    }
                    file_put_contents($backupIndexFile.".".$backName, file_get_contents($indexFile));

                    file_put_contents($indexFile, $indexCode);
                    $msgArr[] = "<span style='color: green'>index.html写入成功</span>";
                }
            } else {
                if (!file_exists($htmlPath) || !is_writable($htmlPath)) {
                    mkdir($htmlPath, 0755, true);
                }
                file_put_contents($indexFile, $indexCode);
                $msgArr[] = "<span style='color: green'>index.html写入成功</span>";
            }
        } else {
            $msgArr[] = "<span style='color:#999999'>未选择index</span>";
        }
        //写入index end

        //写入add start
        if (in_array("add.html", $pagesArray)) {
            if (file_exists($addFile)) {
                if (strpos(file_get_contents($addFile), $tag)) {
                    $msgArr[] = "<span style='color: red'>add.html写入失败，页面已经锁定" . $tag . "</span>";
                } else {
                    if (!file_exists($htmlPath) || !is_writable($htmlPath)) {
                        mkdir($htmlPath, 0755, true);
                    }
                    //先备份
                    if (!file_exists($backupHtmlPath) || !is_writable($backupHtmlPath)) {
                        mkdir($backupHtmlPath, 0755, true);
                    }
                    file_put_contents($backupAddFile.".".$backName, file_get_contents($addFile));

                    file_put_contents($addFile, $addCode);
                    $msgArr[] = "<span style='color: green'>add.html写入成功</span>";
                }
            } else {
                if (!file_exists($htmlPath) || !is_writable($htmlPath)) {
                    mkdir($htmlPath, 0755, true);
                }
                file_put_contents($addFile, $addCode);
                $msgArr[] = "<span style='color: green'>add.html写入成功</span>";
            }
        } else {
            $msgArr[] = "<span style='color:#999999'>未选择add</span>";
        }
        //写入add end

        //写入edit start
        if (in_array("edit.html", $pagesArray)) {
            if (file_exists($editFile)) {
                if (strpos(file_get_contents($editFile), $tag)) {
                    $msgArr[] = "<span style='color: red'>edit.html写入失败，页面已经锁定" . $tag . "</span>";
                } else {
                    if (!file_exists($htmlPath) || !is_writable($htmlPath)) {
                        mkdir($htmlPath, 0755, true);
                    }
                    //先备份
                    if (!file_exists($backupHtmlPath) || !is_writable($backupHtmlPath)) {
                        mkdir($backupHtmlPath, 0755, true);
                    }
                    file_put_contents($backupEditFile.".".$backName, file_get_contents($editFile));

                    file_put_contents($editFile, $editCode);
                    $msgArr[] = "<span style='color: green'>edit.html写入成功</span>";
                }
            } else {
                if (!file_exists($htmlPath) || !is_writable($htmlPath)) {
                    mkdir($htmlPath, 0755, true);
                }
                file_put_contents($editFile, $editCode);
                $msgArr[] = "<span style='color: green'>edit.html写入成功</span>";
            }
        } else {
            $msgArr[] = "<span style='color:#999999'>未选择edit</span>";
        }
        //写入edit end

        return $msgArr;
    }

    public function buildCode($tableName): array
    {
        //查询表的信息
        $tableRs = TableMapper::queryByTableName(['table_name' => $tableName]);
        $listSelectType = $tableRs['list_select_type'];
        if (empty($listSelectType)) {
            $listSelectType = "radio";
        }
        $tableRemarks = $tableRs['table_remarks'];
        //查询该表的字段
        $fieldRs = FieldMapper::queryByTableName(['table_name' => $tableName]);
        $fieldArr = [];
        $selectFieldsArr = [];

        $fieldsBindValueArr = [];
        $fieldSetArr = [];
        $searchWhereArr[] = '<if test="{:id}!=\'\'"> AND id=:id</if>';

        $indexSearchForm = "";
        $addForm = "";
        $editForm = "";
        $indexInitDictData = "";
        $addInitDictData = "";
        $editInitDictData = "";
        $indexInitDbTableData = "";
        $addInitDbTableData = "";
        $editInitDbTableData = "";

        $indexInitTreeParentData = "";
        $addInitTreeParentData = "";
        $editInitTreeParentData = "";
        $initEditor = "";
        $wangEditorJs = "";
        $colsArray[] = '                { type: "' . $listSelectType . '" }';
        $colsArray[] = '                { field: "system_serial_number", title: "序号", width: 60, sort: true, align: "center", type: "numbers" }';
        $mappingArray = [];
        $dictDataRes = "";
        $catalogRes = "";
        $userArray = [];
        foreach ($fieldRs as $v) {

            $fieldName = $v['field_name'];
            $inputType = $v['input_type'];
            $dataCheckType = $v['data_check_type'];
            $dataSrcType = $v['data_src_type'];
            $must = $v['must'];
            $listShow = $v['list_show'];
            $fieldRemarks = $v['field_remarks'];
            $dictCode = $v['dict_code'];
            $customSrc = $v['custom_src'];
            $fieldType = $v['field_type'];
            $customSrcArr = [];
            if (!empty($customSrc)) {
                $customSrcArr = json_decode($customSrc, true);
            }
            $selectFieldsArr[] = $fieldName;
            $fieldArr[] = '                <if test="{:'.$fieldName.'}!==null">'.$fieldName.',</if>';
            $fieldsBindValueArr[] = '                <if test="{:'.$fieldName.'}!==null">:'.$fieldName.',</if>';
            if ($fieldName != 'id') {
                if($dataCheckType=='password'){
                    $fieldSetArr[] = '<if test="{:' . $fieldName . '}!=\'\'">' . $fieldName . '=:' . $fieldName . ',</if>';
                }else{
                    $fieldSetArr[] = '<if test="{:' . $fieldName . '}!==null">' . $fieldName . '=:' . $fieldName . ',</if>';
                }
            }
            //构建serviceImpl 查询 start
            //一对一关系
            //数据库关系
            if ($dataSrcType == "db-table" || $dataSrcType == "tree-parent" || $dataSrcType == 'dict') {
                if ($dataSrcType == 'dict' && $listShow == 1) {
                    $_filedName = Lib::convertUnderline($fieldName, false);
                    $mappingArray[$fieldName] = [
                        'keysArray' => '        $' . $_filedName . 'sArray = [];',
                        'table' => '',
                        'key' => '',
                        'dictCode' => $dictCode,
                        'dataSrcType' => $dataSrcType
                    ];
                } elseif (!empty($customSrcArr) && $listShow == 1) {
                    $api = $customSrcArr['api'];
                    $table = $customSrcArr['table'];
                    $key = $customSrcArr['key'];
                    $value = $customSrcArr['value'];
                    $cut = $customSrcArr['cut'];
                    $_filedName = Lib::convertUnderline($fieldName, false);
                    $mappingArray[$fieldName] = [
                        'keysArray' => '        $' . $_filedName . 'sArray = [];',
                        'table' => $table,
                        'key' => $key,
                        'dictCode' => $dictCode,
                        'dataSrcType' => $dataSrcType
                    ];
                }
            }
//            if ($dataSrcType == "tree-parent" && $listShow == 1) {
//                //$userArray[] = "use modules\sys\mapper\CatalogMapper;".PHP_EOL;
//                //$catalogRes = '            //加载目录分类缓存'.PHP_EOL.'            $catalogRes = CatalogMapper::lists();' . PHP_EOL;
//                $catalogRes = '            //从redis或数据库中加载目录分类缓存' . PHP_EOL . '            $catalogRes = GetCacheComponent::catalog();'.PHP_EOL.'            $catalogRes = array_column($catalogRes, NULL, "id");' . PHP_EOL;
//            }
//            //数据字典关系
//            if ($dataSrcType == "dict" && !empty($dictCode) && $listShow == 1) {
//                //设置数据字典
//                $userArray[] = "use modules\sys\component\GetCacheComponent;" . PHP_EOL;
//                $dictDataRes = '            //从redis或数据库中加载数据字典缓存' . PHP_EOL . '            $dictDataRes = GetCacheComponent::dictData();' . PHP_EOL;
//
//            }

            //构建serviceImpl 查询 end

            //xml 查询条件处理 $searchWhere start
            $searchCondition = $v['search_condition'];
            if ($searchCondition == 'equals') {
                $searchWhereArr[] = '<if test="{:' . $fieldName . '}!=\'\'"> AND ' . $fieldName . '=:' . $fieldName . '</if>';
            } elseif ($searchCondition == 'like') {
                $searchWhereArr[] = '<if test="{:' . $fieldName . '}!=\'\'"> AND ' . $fieldName . ' LIKE CONCAT(\'%\',:' . $fieldName . ',\'%\')</if>';
            } elseif ($searchCondition == 'likeLeft') {
                $searchWhereArr[] = '<if test="{:' . $fieldName . '}!=\'\'"> AND ' . $fieldName . ' LIKE CONCAT(\'%\',:' . $fieldName . ')</if>';
            } elseif ($searchCondition == 'likeRight') {
                $searchWhereArr[] = '<if test="{:' . $fieldName . '}!=\'\'"> AND ' . $fieldName . ' LIKE CONCAT(:' . $fieldName . ',\'%\')</if>';
            } elseif ($searchCondition == '>=') {
                $searchWhereArr[] = '<if test="{:' . $fieldName . '}!=\'\'"> AND ' . $fieldName . ' &gt;=:' . $fieldName . '</if>';
            } elseif ($searchCondition == '<=') {
                $searchWhereArr[] = '<if test="{:' . $fieldName . '}!=\'\'"> AND ' . $fieldName . ' &lt;=:' . $fieldName . '</if>';
            } elseif ($searchCondition == 'between') {
                $searchWhereArr[] = '<if test="{:' . $fieldName . '_between_start}!=\'\' and {:' . $fieldName . '_between_end}!=\'\'"> AND (' . $fieldName . ' BETWEEN :' . $fieldName . '_between_start AND :' . $fieldName . '_between_end)</if>';
            } elseif ($searchCondition == 'find_in_set') {
                $searchWhereArr[] = '<if test="{:' . $fieldName . '}!=\'\'"> AND (<foreach item="item" from="{:' . $fieldName . '}" split="," separator="or">find_in_set(:item,' . $fieldName . ')</foreach>)</if>';
            }
            //xml 查询条件处理 $searchWhere end

            $mustTag = "";
            $layVerify = "";
            if ($must == 1) {
                if ($inputType == "radio" || $inputType == "checkbox") {
                    $layVerify = "otherReq";
                } else {
                    $layVerify = "required";
                }
                $mustTag = "<b style='color:red'>*</b>";
            }

            //处理表单内容 检索，添加，编辑 start
            if ($inputType == 'input') {
                $searchDateClass = "";
                $dateAttr = "range=\"\"";
                $spStartEnd = "";
                $readonly = "";
                if ($searchCondition != 'none') {
                    $dateBetweenInput = "";
                    if ($dataCheckType == "ymd") {
                        $searchDateClass = "date";
                        $spStartEnd = "";
                    } elseif ($dataCheckType == "ymdhis" || $dataCheckType == 'time') {
                        $searchDateClass = "datetime";
                        $dateAttr = "range=\"~\"";
                        $spStartEnd = "";
                    } elseif ($dataCheckType == 'timeMs') {
                        $searchDateClass = "datetime";
                        $dateAttr = "range=\"~\"";
                        $spStartEnd = "000~999";
                    } elseif ($dataCheckType == "his") {
                        $searchDateClass = "time";
                        $spStartEnd = "";
                    }
                    if ($searchCondition == "between") {
                        $readonly = "readonly";
                        $dateBetweenInput .= '                     <input type="hidden" name="' . $fieldName . '_between_start">' . PHP_EOL;
                        $dateBetweenInput .= '                     <input type="hidden" name="' . $fieldName . '_between_end">' . PHP_EOL;
                    }
                    $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
                    $indexSearchForm .= '                     <input name="' . $fieldName . '" placeholder="' . $fieldRemarks . '" ' . $readonly . ' data-check-type="' . $dataCheckType . '" ' . $dateAttr . ' sp-start-end="' . $spStartEnd . '" class="layui-input ' . $searchDateClass . '" autocomplete="off">' . PHP_EOL;
                    $indexSearchForm .= $dateBetweenInput;
                    $indexSearchForm .= '                </div>' . PHP_EOL;
                }
                //设置添加表单
                if ($fieldName != 'id' && $fieldName != 'create_time' && $fieldName != 'update_time') {
                    $_inputType = "text";
                    $defaultDate = "";
                    $dateClass = "";
                    if ($dataCheckType == "money" || $dataCheckType == "int" || $dataCheckType == "float") {
                        $_inputType = "number";
                    }

                    if ($dataCheckType == "ymd") {
                        $dateClass = "date";
                        $defaultDate = 'default-date="now"';
                    }
                    if ($dataCheckType == "ymdhis") {
                        $dateClass = "datetime";
                        $defaultDate = 'default-date="now"';
                    }
                    if ($dataCheckType == "time") {
                        $dateClass = "datetime";
                        $defaultDate = 'default-date="now"';
                    }
                    if ($dataCheckType == "timeMs") {
                        $dateClass = "datetime";
                        $defaultDate = 'default-date="now"';
                    }
                    if ($dataCheckType == "ymdhis") {
                        $dateClass = "datetime";
                        $defaultDate = 'default-date="now"';
                    }
                    if ($dataCheckType == "his") {
                        $dateClass = "time";
                        $defaultDate = 'default-date="now"';
                    }
                    $addForm .= '            <div class="layui-col-md6">' . PHP_EOL;
                    $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                    $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                    $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                    $addForm .= '                       <input type="' . $_inputType . '" name="' . $fieldName . '" ' . $defaultDate . '  lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请输入' . $fieldRemarks . '" placeholder="请输入' . $fieldRemarks . '" autocomplete="off" class="layui-input data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . ' ' . $dateClass . '">' . PHP_EOL;
                    $addForm .= '                    </div>' . PHP_EOL;
                    $addForm .= '                </div>' . PHP_EOL;
                    $addForm .= '            </div>' . PHP_EOL;

                    //设置修改表单

                    $editForm .= '                    <div class="layui-col-md6">' . PHP_EOL;
                    $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                    if ($dataCheckType == 'password') {
                        $editForm .= '                            <label class="layui-form-label">' . $fieldRemarks . '</label>' . PHP_EOL;
                    } else {
                        $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                    }
                    $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                    if ($dataCheckType == 'password') {
                        $editForm .= '                              <input type="' . $_inputType . '" name="' . $fieldName . '" value="" ' . $defaultDate . ' lay-verType="msg"  lay-reqtext="请输入' . $fieldRemarks . '" placeholder="为空不修改" autocomplete="off" class="layui-input data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . ' ' . $dateClass . '">' . PHP_EOL;
                    } else {
                        $editForm .= '                              <input type="' . $_inputType . '" name="' . $fieldName . '" value="<%:=data.' . $fieldName . '%>" ' . $defaultDate . ' lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请输入' . $fieldRemarks . '" placeholder="请输入' . $fieldRemarks . '" autocomplete="off" class="layui-input data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . ' ' . $dateClass . '">' . PHP_EOL;
                    }
                    $editForm .= '                            </div>' . PHP_EOL;
                    $editForm .= '                        </div>' . PHP_EOL;
                    $editForm .= '                    </div>' . PHP_EOL;
                }
            } elseif ($inputType == 'select') {
                $selectAttr = "";
                $cssClass = "";
                if ($dataSrcType == "dict" && $dictCode != "") {
                    //原生下拉数据字典
                    $selectAttr = 'dict-code="' . $dictCode . '"';
                    $cssClass = 'class="dict-select"';
                    if ($searchCondition != "none") {
                        $indexInitDictData = "initDictData('search');";
                    }
                    $addInitDictData = "initDictData('add');";
                    $editInitDictData = "initDictData('edit');";
                } else if ($dataSrcType == "db-table") {
                    //原生下拉一对一数据库
                    $selectAttr = 'api="接口未定义"';
                    $cssClass = 'class="db-table-select data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    if (!empty($customSrcArr)) {
                        $api = $customSrcArr['api'];
                        $key = $customSrcArr['key'];
                        $value = $customSrcArr['value'];
                        $cut = $customSrcArr['cut'];
                        $selectAttr = 'api="' . $api . '"  key="' . $key . '" val="' . $value . '" cut="' . $cut . '"';
                    }
                    if ($searchCondition != "none") {
                        $indexInitDbTableData = "initDbTableData('search');";
                    }
                    $addInitDbTableData = "initDbTableData('add');";
                    $editInitDbTableData = "initDbTableData('edit');";
                }
                //设置搜索表单
                if ($searchCondition != "none") {
                    $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
                    $indexSearchForm .= '                    <select name="' . $fieldName . '" tips="' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . '>' . PHP_EOL;
                    $indexSearchForm .= '                        <option value="">' . $fieldRemarks . '</option>' . PHP_EOL;
                    $indexSearchForm .= '                    </select>' . PHP_EOL;
                    $indexSearchForm .= '                </div>' . PHP_EOL;
                }
                //设置添加表单
                $addForm .= '            <div class="layui-col-md6">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <select name="' . $fieldName . '" lay-verType="msg" tips="请选择' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' lay-verify="' . $layVerify . '" lay-reqtext="请选择' . $fieldRemarks . '">' . PHP_EOL;
                $addForm .= '                           <option value=""> 请选择' . $fieldRemarks . '</option>' . PHP_EOL;
                $addForm .= '                        </select>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md6">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                                <select name="' . $fieldName . '" selected-value="<%:=data.' . $fieldName . '%>" lay-verType="msg" tips="请选择' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' lay-verify="' . $layVerify . '" lay-reqtext="请选择' . $fieldRemarks . '">' . PHP_EOL;
                $editForm .= '                                   <option value=""> 请选择' . $fieldRemarks . '</option>' . PHP_EOL;
                $editForm .= '                                </select>' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if ($inputType == "xmSelectNoPage" || $inputType == "xmMultiSelectNoPage") {
                //下拉选择无分页（下拉单选和下拉多选）
                $selectAttr = "";
                $cssClass = "";
                if ($dataSrcType == "dict" && $dictCode != "") {
                    //数据字典
                    $selectAttr = 'dict-code="' . $dictCode . '"';
                    $cssClass = 'class="dict-' . $inputType . ' data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    if ($searchCondition != 'none') {
                        $indexInitDictData = "initDictData('search');";
                    }
                    $addInitDictData = "initDictData('add');";
                    $editInitDictData = "initDictData('edit');";
                } else if ($dataSrcType == "db-table") {
                    //数据库
                    $selectAttr = "api=\"接口未定义\"";
                    if (!empty($customSrcArr)) {
                        $api = $customSrcArr['api'];
                        $key = $customSrcArr['key'];
                        $value = $customSrcArr['value'];
                        $cut = $customSrcArr['cut'];
                        $selectAttr = 'api="' . $api . '"  key="' . $key . '" val="' . $value . '" cut="' . $cut . '"';
                    }

                    $cssClass = 'class="db-table-' . $inputType . ' data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    if ($searchCondition != "none") {
                        $indexInitDbTableData = "initDbTableData('search');";
                    }
                    $addInitDbTableData = "initDbTableData('add');";
                    $editInitDbTableData = "initDbTableData('edit');";
                } else if ($dataSrcType == "tree-parent") {
                    //树表parent字段
                    $selectAttr = "api=\"接口未定义\"";
                    if (!empty($customSrcArr)) {
                        $api = $customSrcArr['api'];
                        $key = $customSrcArr['key'];
                        $value = $customSrcArr['value'];
                        $cut = $customSrcArr['cut'];
                        $pid = $customSrcArr['pid'] ?? "0";
                        $selectAttr = 'api="' . $api . '"  key="' . $key . '" val="' . $value . '" cut="' . $cut . '" pid="' . $pid . '"';
                    }
                    $cssClass = 'class="tree-parent-' . $inputType . ' data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    if ($searchCondition != "none") {
                        $indexInitTreeParentData = "initTreeParentData('search');";
                    }
                    $addInitTreeParentData = "initTreeParentData('add');";
                    $editInitTreeParentData = "initTreeParentData('edit');";
                }
                if ($searchCondition != "none") {
                    $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
                    $indexSearchForm .= '                    <div id="' . $fieldName . '" name="' . $fieldName . '" tips="' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' style="min-width:200px;max-width: 600px;"></div>' . PHP_EOL;
                    $indexSearchForm .= '                </div>' . PHP_EOL;
                }
                //设置添加表单
                //设置添加表单
                $addForm .= '            <div class="layui-col-md6">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <div style="min-width:200px;" id="' . $fieldName . '" name="' . $fieldName . '" tips="请选择' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' lup-lay-verify="' . $layVerify . '" lay-reqText="请选择' . $fieldRemarks . '"></div>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md6">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                                <div style="min-width:200px;" selected-value="<%:=data.' . $fieldName . '%>" id="' . $fieldName . '" name="' . $fieldName . '" tips="请选择' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' lup-lay-verify="' . $layVerify . '" lay-reqText="请选择' . $fieldRemarks . '"></div>' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if ($inputType == "xmSelect" || $inputType == "xmMultiSelect") {
                //下拉有分页
                if ($dataSrcType == "db-table") {

                    $search = "";
                    $selectAttr = 'api="接口未定义';

                    if (!empty($customSrcArr)) {
                        $api = $customSrcArr['api'];
                        $key = $customSrcArr['key'];
                        $value = $customSrcArr['value'];
                        $cut = $customSrcArr['cut'];
                        $search = $customSrcArr['search'];
                        $selectAttr = 'api="' . $api . '"  key="' . $key . '" val="' . $value . '" cut="' . $cut . '"';
                    }
                    $cssClass = 'class="db-table-' . $inputType . ' data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    if ($searchCondition != "none") {
                        $indexInitDbTableData = "initDbTableData('search');";
                    }
                    $addInitDbTableData = "initDbTableData('add');";
                    $editInitDbTableData = "initDbTableData('edit');";
                    if ($searchCondition != "none") {
                        $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
                        $indexSearchForm .= '                    <div id="' . $fieldName . '" search="' . $search . '" name="' . $fieldName . '" tips="' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' style="min-width:200px"></div>' . PHP_EOL;
                        $indexSearchForm .= '                </div>' . PHP_EOL;
                    }

                    //设置添加表单
                    $addForm .= '            <div class="layui-col-md6">' . PHP_EOL;
                    $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                    $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                    $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                    $addForm .= '                        <div style="min-width:200px;" search="' . $search . '" id="' . $fieldName . '" name="' . $fieldName . '" tips="请选择' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' lup-lay-verify="' . $layVerify . '" lay-reqText="请选择' . $fieldRemarks . '"></div>' . PHP_EOL;
                    $addForm .= '                    </div>' . PHP_EOL;
                    $addForm .= '                </div>' . PHP_EOL;
                    $addForm .= '            </div>' . PHP_EOL;

                    //设置编辑表单
                    $editForm .= '                    <div class="layui-col-md6">' . PHP_EOL;
                    $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                    $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                    $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                    $editForm .= '                                <div style="min-width:200px;" search="' . $search . '" set-value="<%:=encodeURIComponent(JSON.stringify(data.' . $fieldName . '_res))%>" selected-value="<%:=data.' . $fieldName . '%>" id="' . $fieldName . '" name="' . $fieldName . '" tips="请选择' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' lup-lay-verify="' . $layVerify . '" lay-reqText="请选择' . $fieldRemarks . '"></div>' . PHP_EOL;
                    $editForm .= '                            </div>' . PHP_EOL;
                    $editForm .= '                        </div>' . PHP_EOL;
                    $editForm .= '                    </div>' . PHP_EOL;
                }
            } else if ($inputType == "textEditor") {
                //富文本编辑器，这里用wangEditor
                $wangEditorJs = '<script src="../../../js/wangEditor.min.js"></script>' . PHP_EOL . '<!--<script src="../../../js/xss.min.js"></script>-->' . PHP_EOL;
                $initEditor .= 'editor("' . $fieldName . '");' . PHP_EOL;
                if ($searchCondition != "none") {
                    $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
                    $indexSearchForm .= '                    <input class="layui-input" name="' . $fieldName . '" placeholder="' . $fieldRemarks . '" autocomplete="off">' . PHP_EOL;
                    $indexSearchForm .= '                </div>' . PHP_EOL;
                }
                //设置添加表单
                $addForm .= '            <div class="layui-col-md12">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <textarea style="visibility: hidden; height: 0px !important;top: 0px;position:absolute;" name="' . $fieldName . '" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请输入' . $fieldRemarks . '" placeholder="请输入' . $fieldRemarks . '" autocomplete="off"></textarea>' . PHP_EOL;
                $addForm .= '                        <div id="' . $fieldName . '" style="min-width:400px;"></div>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md12">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                                <textarea style="visibility: hidden; height: 0px !important;top: 0px;position:absolute;" name="' . $fieldName . '" lay-verType="msg" lay-verify="' . $layVerify . '"  lay-reqtext="请输入' . $fieldRemarks . '" placeholder="请输入' . $fieldRemarks . '" autocomplete="off"><%:=data.' . $fieldName . '%></textarea>' . PHP_EOL;
                $editForm .= '                                <div id="' . $fieldName . '" style="min-width:400px;"><%:=decodeEntities(data.' . $fieldName . ')%></div>' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if ($inputType == "textarea") {
                if ($searchCondition != "none") {
                    $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
                    $indexSearchForm .= '                    <input class="layui-input" name="' . $fieldName . '" placeholder="' . $fieldRemarks . '" autocomplete="off">' . PHP_EOL;
                    $indexSearchForm .= '                </div>' . PHP_EOL;
                }
                //设置添加表单
                $addForm .= '            <div class="layui-col-md12">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <textarea  name="' . $fieldName . '" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请输入' . $fieldRemarks . '" placeholder="请输入' . $fieldRemarks . '" autocomplete="off" class="layui-textarea data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"></textarea>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                   <div class="layui-col-md12">' . PHP_EOL;
                $editForm .= '                       <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                           <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                           <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                               <textarea name="' . $fieldName . '" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请输入' . $fieldRemarks . '" placeholder="请输入' . $fieldRemarks . '" autocomplete="off" class="layui-textarea data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"><%:=data.' . $fieldName . '%></textarea>' . PHP_EOL;
                $editForm .= '                           </div>' . PHP_EOL;
                $editForm .= '                       </div>' . PHP_EOL;
                $editForm .= '                   </div>' . PHP_EOL;
            } else if ($inputType == "singleFile") {
                //单附件信息
                $exts = $customSrcArr['exts'];
                $path = $customSrcArr['path'];
                $thumb = $customSrcArr['thumb'];
                //设置添加表单
                $addForm .= '            <div class="layui-col-md6">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <input type="text" onclick="openUploadFileBox(this,\'\')" thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请上传' . $fieldRemarks . '" placeholder="请上传' . $fieldRemarks . '" autocomplete="off" class="layui-input upload data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '">' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md6">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                                <input type="text" onclick="openUploadFileBox(this,\'\')" thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '"  name="' . $fieldName . '" value="<%:=data.' . $fieldName . '%>" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请上传' . $fieldRemarks . '" placeholder="请上传' . $fieldRemarks . '" autocomplete="off" class="layui-input upload data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '">' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if ($inputType == "multiFile") {
                //多附件上传
                $exts = $customSrcArr['exts'];
                $path = $customSrcArr['path'];
                $thumb = $customSrcArr['thumb'];
                //设置添加表单
                $addForm .= '            <div class="layui-col-md12">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <div thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '" lup-lay-verify="' . $layVerify . '" lay-reqtext="请上传' . $fieldRemarks . '" placeholder="请上传' . $fieldRemarks . '" class="multiFile"></div>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md12">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                                <div thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '" value="<%:=data.' . $fieldName . '%>" lup-lay-verify="' . $layVerify . '" lay-reqtext="请上传' . $fieldRemarks . '" placeholder="请上传' . $fieldRemarks . '" class="multiFile"></div>' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if ($inputType == "singleFileRemarks") {
                //单附件上传带描述
                $exts = $customSrcArr['exts'];
                $path = $customSrcArr['path'];
                $thumb = $customSrcArr['thumb'];
                //设置添加表单
                $addForm .= '            <div class="layui-col-md12">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block" style="display: flex;">' . PHP_EOL;
                $addForm .= '                        <textarea style="display:none" name="' . $fieldName . '" class="singleFileRemarksValue"></textarea>' . PHP_EOL;
                $addForm .= '                        <div style="display: flex;width: 40%;min-width: 100px;position: relative;">' . PHP_EOL;
                $addForm .= '                            <input type="text" ori-name=name="' . $fieldName . '" single-file-remarks-type="file" onclick="openUploadFileBox(this,\'\')" thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '_file" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请上传' . $fieldRemarks . '" placeholder="请上传' . $fieldRemarks . '" autocomplete="off" class="layui-input upload singleFileRemarks_file">' . PHP_EOL;
                $addForm .= '                        </div>' . PHP_EOL;
                $addForm .= '                        <div style="display: flex;flex: 1;min-width: 100px;padding-left: 10px;">' . PHP_EOL;
                $addForm .= '                            <input type="text" ori-name="' . $fieldName . '" single-file-remarks-type="remarks" thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '_remarks" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请输入' . $fieldRemarks . '描述" placeholder="请输入' . $fieldRemarks . '描述" autocomplete="off" class="layui-input singleFileRemarks_remarks">' . PHP_EOL;
                $addForm .= '                        </div>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md12">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block" style="display: flex;">' . PHP_EOL;
                $editForm .= '                                <textarea style="display:none" name="' . $fieldName . '" class="singleFileRemarksValue"><%:=data.' . $fieldName . '%></textarea>' . PHP_EOL;
                $editForm .= '                                <div style="display: flex;width: 40%;min-width: 100px;position: relative;">' . PHP_EOL;
                $editForm .= '                                    <input type="text" ori-name="' . $fieldName . '" single-file-remarks-type="file" onclick="openUploadFileBox(this,\'\')" thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '_file" value="" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请上传' . $fieldRemarks . '" placeholder="请上传' . $fieldRemarks . '" autocomplete="off" class="layui-input upload singleFileRemarks_file">' . PHP_EOL;
                $editForm .= '                                </div>' . PHP_EOL;
                $editForm .= '                                <div style="display: flex;flex: 1;min-width: 100px;padding-left: 10px;">' . PHP_EOL;
                $editForm .= '                                    <input type="text" ori-name="' . $fieldName . '" single-file-remarks-type="remarks" thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '_remarks" lay-verType="msg" lay-verify="' . $layVerify . '" lay-reqtext="请输入' . $fieldRemarks . '描述" placeholder="请输入' . $fieldRemarks . '描述" autocomplete="off" class="layui-input singleFileRemarks_remarks">' . PHP_EOL;
                $editForm .= '                                </div>' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if ($inputType == "multiFileRemarks") {
                //多附件带描述上传
                $exts = $customSrcArr['exts'];
                $path = $customSrcArr['path'];
                $thumb = $customSrcArr['thumb'];
                //设置添加表单
                $addForm .= '            <div class="layui-col-md12">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <div thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '" lup-lay-verify="' . $layVerify . '" lay-reqtext="请上传' . $fieldRemarks . '" placeholder="请上传' . $fieldRemarks . '" class="multiFileRemarks"></div>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md12">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                                <div thumb="' . $thumb . '" path="' . $path . '" exts="' . $exts . '" name="' . $fieldName . '" value="<%:=encodeURIComponent(data.' . $fieldName . ')%>" lup-lay-verify="' . $layVerify . '" lay-reqtext="请上传' . $fieldRemarks . '" placeholder="请上传' . $fieldRemarks . '" class="multiFileRemarks"></div>' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if ($inputType == "radio") {
                //单选按钮
                //获取数据字典
                $selectAttr = "";
                $cssClass = "";
                $cssClassRadio = "";
                if ($dataSrcType == "dict" && !empty($dictCode)) {
                    $selectAttr = 'dict-code="' . $dictCode . '"';
                    $cssClass = 'class="dict-select"';
                    $cssClassRadio = 'class="dict-radio layui-input data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    if ($searchCondition != "none") {
                        $indexInitDictData = "initDictData('search');";
                    }
                    $addInitDictData = "initDictData('add');";
                    $editInitDictData = "initDictData('edit');";
                } else if ($dataSrcType == "db-table") {
                    //一对一数据库
                    $selectAttr = 'api="接口未定义"';
                    if (!empty($customSrcArr)) {
                        $api = $customSrcArr['api'];
                        $key = $customSrcArr['key'];
                        $value = $customSrcArr['value'];
                        $cut = $customSrcArr['cut'];
                        $selectAttr = 'api="' . $api . '"  key="' . $key . '" val="' . $value . '" cut="' . $cut . '"';
                    }
                    $cssClass = 'class="db-table-select"';
                    $cssClassRadio = 'class="db-table-radio layui-input data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    if ($searchCondition != "none") {
                        $indexInitDbTableData = "initDbTableData('search');";
                    }
                    $addInitDbTableData = "initDbTableData('add');";
                    $editInitDbTableData = "initDbTableData('edit');";
                }
                if ($searchCondition != "none") {
                    $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
                    $indexSearchForm .= '                    <select name="' . $fieldName . '" tips="' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . '>' . PHP_EOL;
                    $indexSearchForm .= '                        <option value="">' . $fieldRemarks . '</option>' . PHP_EOL;
                    $indexSearchForm .= '                    </select>' . PHP_EOL;
                    $indexSearchForm .= '                </div>' . PHP_EOL;
                }
                //设置添加表单
                $addForm .= '            <div class="layui-col-md6">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <div name="' . $fieldName . '" lay-verType="msg" tips="请选择' . $fieldRemarks . '" ' . $cssClassRadio . ' ' . $selectAttr . ' lup-lay-verify="' . $layVerify . '" lay-reqtext="请选择' . $fieldRemarks . '"></div>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md6">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                                <div selected-value="<%:=data.' . $fieldName . '%>" lay-verType="msg" name="' . $fieldName . '" tips="请选择' . $fieldRemarks . '" ' . $cssClassRadio . ' ' . $selectAttr . ' lup-lay-verify="' . $layVerify . '" lay-reqtext="请选择' . $fieldRemarks . '"></div>' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if ($inputType == "checkbox") {
                $cssClass = '';
                $selectAttr = "";
                $cssClassCheckbox = "";
                if ($dataSrcType == "dict" && !empty($dictCode)) {
                    $cssClass = 'class="dict-xmMultiSelectNoPage"';
                    $selectAttr = 'dict-code="' . $dictCode . '"';
                    if ($searchCondition != "none") {
                        $indexInitDictData = "initDictData('search');";
                    }
                    $cssClassCheckbox = 'class="dict-checkbox layui-input data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    $addInitDictData = "initDictData('add');";
                    $editInitDictData = "initDictData('edit');";
                } else if ($dataSrcType == "db-table") {
                    //一个一数据库
                    $selectAttr = 'api="接口未定义"';
                    $cssClass = 'class="db-table-xmMultiSelectNoPage"';
                    if (!empty($customSrcArr)) {
                        $api = $customSrcArr['api'];
                        $key = $customSrcArr['key'];
                        $value = $customSrcArr['value'];
                        $cut = $customSrcArr['cut'];
                        $selectAttr = 'api="' . $api . '"  key="' . $key . '" val="' . $value . '" cut="' . $cut . '"';
                    }
                    $cssClassCheckbox = 'class="db-table-checkbox layui-input data-check-type-' . $dataCheckType . ' field-type-' . $fieldType . '"';
                    if ($searchCondition != "none") {
                        $indexInitDbTableData = "initDbTableData('search');";
                    }
                    $addInitDbTableData = "initDbTableData('add');";
                    $editInitDbTableData = "initDbTableData('edit');";
                }
                if ($searchCondition != "none") {
                    $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
                    $indexSearchForm .= '                    <div id="' . $fieldName . '" name="' . $fieldName . '" tips="' . $fieldRemarks . '" ' . $cssClass . ' ' . $selectAttr . ' style="min-width:200px"></div>' . PHP_EOL;
                    $indexSearchForm .= '                </div>' . PHP_EOL;
                }
                //设置添加表单
                $addForm .= '            <div class="layui-col-md6">' . PHP_EOL;
                $addForm .= '                <div class="layui-form-item">' . PHP_EOL;
                $addForm .= '                    <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $addForm .= '                    <div class="layui-input-block">' . PHP_EOL;
                $addForm .= '                        <div name="' . $fieldName . '" lay-verType="msg" tips="请选择' . $fieldRemarks . '" ' . $cssClassCheckbox . ' ' . $selectAttr . ' lup-lay-verify="' . $layVerify . '" lay-reqtext="请选择' . $fieldRemarks . '"></div>' . PHP_EOL;
                $addForm .= '                    </div>' . PHP_EOL;
                $addForm .= '                </div>' . PHP_EOL;
                $addForm .= '            </div>' . PHP_EOL;

                //设置编辑表单
                $editForm .= '                    <div class="layui-col-md6">' . PHP_EOL;
                $editForm .= '                        <div class="layui-form-item">' . PHP_EOL;
                $editForm .= '                            <label class="layui-form-label">' . $mustTag . ' ' . $fieldRemarks . '</label>' . PHP_EOL;
                $editForm .= '                            <div class="layui-input-block">' . PHP_EOL;
                $editForm .= '                                <div selected-value="<%:=data.' . $fieldName . '%>" lay-verType="msg" name="' . $fieldName . '" tips="请选择' . $fieldRemarks . '" ' . $cssClassCheckbox . ' ' . $selectAttr . ' lup-lay-verify="' . $layVerify . '" lay-reqtext="请选择' . $fieldRemarks . '"></div>' . PHP_EOL;
                $editForm .= '                            </div>' . PHP_EOL;
                $editForm .= '                        </div>' . PHP_EOL;
                $editForm .= '                    </div>' . PHP_EOL;
            } else if (inputType . equals("xxx")) {
                //其他类型
            }
            //处理index.html 显示字段信息
            $widthStr = "";
            if ($v['cols_width'] > 0) {
                $widthStr = "width: " . $v['cols_width'] . ", ";
            }
            $listEditStr = "";
            if ($v['list_edit'] == 1) {
                $listEditStr = "edit: true, ";
            }
            if ($v['list_show'] == 1 || $fieldName == 'id') {
                $templet = "";
                if ($dataSrcType == "dict") {
                    $templet = ', templet: function(d) { return listDictData("' . $dictCode . '", d.' . $fieldName . ') }';
                }
                if ($dataSrcType == "db-table" || $dataSrcType == 'tree-parent') {
                    $_customSrcValue = $customSrcArr['value'];
                    $_customSrcCut = $customSrcArr['cut'];
                    $templet = ', templet: function(d) { return listResData("' . $_customSrcValue . '", "' . $_customSrcCut . '", d.' . $fieldName . '_res) }';
                }
                $hidden = "";
                if ($fieldName == 'id') {
                    $hidden = " hide: true, width: 100,";
                }
                if ($inputType == 'singleFile' || $inputType == 'multiFile' || $inputType == 'singleFileRemarks' || $inputType == 'multiFileRemarks') {
                    $templet = ', templet: function(d) { return listUpload(d.id+"_' . $fieldName . '", d.' . $fieldName . ', "") }';
                }
                if ($dataCheckType == 'time' || $dataCheckType == 'timeMs') {
                    $templet = ', templet: function(d) { return timeStampFmt(d.' . $fieldName . ') }';
                }
                if ($dataCheckType == 'ymd' || $dataCheckType == 'ymdhis') {
                    $templet = ', templet: function(d) { return dateFormat(d.' . $fieldName . ') }';
                }
                $colsArray[] = '                { field: "' . $fieldName . '", title: "' . $fieldRemarks . '",' . $hidden . ' ' . $widthStr . 'sort: true, ' . $listEditStr . 'align: "left"' . $templet . ' }';
            }
            //处理表单内容  end
        }

        $fields = implode(PHP_EOL, $fieldArr);
        $fieldsBindValue = implode(PHP_EOL, $fieldsBindValueArr);

        $selectFields = implode(",",$selectFieldsArr);
        $fieldSet = implode(PHP_EOL . "            ", $fieldSetArr);
        $searchWhere = implode(PHP_EOL . "            ", $searchWhereArr);
        $tableNameArr = explode("_", $tableName);
        $prefix = $tableNameArr[0];
        $arr = [];
        foreach ($tableNameArr as $k => $v) {
            if ($k > 0) {
                $arr[] = ucfirst($v);
            }
        }
        $bigTableName = implode("", $arr);
        $smallTableName = lcfirst($bigTableName);

        //获取该空间下是否有custom.js
        $customJsPath = APP_PATH . "public/lup-mis/pages/" . $prefix . "/" . $smallTableName . "/custom.js";

        $path = APP_PATH . "resources/generate/";
        $filter = file_get_contents($path . "Filter.php.template");
        $controller = file_get_contents($path . "Controller.php.template");
        $service = file_get_contents($path . "Service.php.template");
        $serviceImpl = file_get_contents($path . "ServiceImpl.php.template");
        $mapper = file_get_contents($path . "Mapper.php.template");
        $xml = file_get_contents($path . "mapper.xml.template");
        $index = file_get_contents($path . "index.html.template");
        $add = file_get_contents($path . "add.html.template");
        $edit = file_get_contents($path . "edit.html.template");

        $filter = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $filter);
        $filter = str_replace('{$Prefix}', ucfirst($prefix), $filter);

        $controller = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $controller);
        $controller = str_replace('{$prefix}', $prefix, $controller);
        $controller = str_replace('{$Name}', $bigTableName, $controller);
        $controller = str_replace('{$name}', $smallTableName, $controller);

        $service = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $service);
        $service = str_replace('{$Name}', $bigTableName, $service);
        $service = str_replace('{$prefix}', $prefix, $service);

        $foreachMapping = "";
        $mappingRes = "";
        $foreachBind = "";
        $mappingResQuery = "";

        $foreachBindQuery = "";
        $keysArray = [];
        if (!empty($mappingArray)) {
            //print_r($mappingArray);
            $foreachMapping .= '        //取出数据库对应关系的字段的值（这里用逗号隔开）' . PHP_EOL . '        foreach ($rows as $v) {' . PHP_EOL;
            foreach ($mappingArray as $k => $v) {
                if ($v['dataSrcType'] == 'db-table') {
                    $keysArray[] = $v['keysArray'];
                    $table = $customSrcArr['table'] ?? $v['table'];
                    $_tableNameArr = explode("_", $table);
                    //print_r($_tableNameArr);
                    $_prefix = $_tableNameArr[0];
                    $_arr = [];
                    foreach ($_tableNameArr as $_k => $_v) {
                        if ($_k > 0) {
                            $_arr[] = ucfirst($_v);
                        }
                    }
                    $_bigTableName = implode("", $_arr);
                    $_smallTableName = lcfirst($_bigTableName);
                    $foreachMapping .= '            $' . Lib::convertUnderline($k, false) . 'sArray[] = $v[\'' . $k . '\'];' . PHP_EOL;
                    $userArray[] = 'use modules\\' . $_prefix . '\\mapper\\' . $_bigTableName . 'Mapper;' . PHP_EOL;
                    $mappingRes .= '        //将数据表' . $_smallTableName . '中根据id字段取出符合符合条件的数据，并以id作为主键' . PHP_EOL . '        $' . $_smallTableName . 'Res = array_column(' . $_bigTableName . 'Mapper::listsIn([\'ids\' => implode(\',\', $' . Lib::convertUnderline($k, false) . 'sArray)]), NULL, \'id\');' . PHP_EOL;
                    $mappingResQuery .= '        //将数据表' . $_smallTableName . '中根据id字段取出符合符合条件的数据，并以id作为主键' . PHP_EOL . '        $' . $_smallTableName . 'Res = array_column(' . $_bigTableName . 'Mapper::listsIn([\'ids\' => $query[\''.$k.'\']]), NULL, \'id\');' . PHP_EOL;

                }
            }
            $foreachMapping .= '        }' . PHP_EOL;
            $foreachBindQuery .= '        //根据上面取出的符合条件的数据开始绑定映射关系' . PHP_EOL;

            $foreachBind .= '        //根据上面取出的符合条件的数据开始绑定映射关系' . PHP_EOL . '        foreach ($rows as $k => $v) {' . PHP_EOL;
            foreach ($mappingArray as $k => $v) {
                $_dictCode = $v['dictCode'];
                $table = $customSrcArr['table'] ?? $v['table'];
                $_dataSrcType = $v['dataSrcType'];
                $_tableNameArr = explode("_", $table);
                $_arr = [];
                foreach ($_tableNameArr as $_k => $_v) {
                    if ($_k > 0) {
                        $_arr[] = ucfirst($_v);
                    }
                }
                $_bigTableName = implode("", $_arr);
                $_smallTableName = lcfirst($_bigTableName);
                if ($_dataSrcType == 'tree-parent') {
                    $userArray[] = 'use application\\component\\DataComponent;' . PHP_EOL;
                    $foreachBind .= '            $rows[$k][\'' . $k . '_res\'] = DataComponent::getCatalog($v[\'' . $k . '\']);' . PHP_EOL;
                    $foreachBindQuery .= '        $query[\'' . $k . '_res\'] = DataComponent::getCatalog($query[\'' . $k . '\']);' . PHP_EOL;
                } elseif ($_dataSrcType == 'dict') {
                    $userArray[] = "use application\\component\\DataComponent;" . PHP_EOL;

                    $foreachBind .= '            $rows[$k][\'' . $k . '_res\'] = DataComponent::getDictData($v[\'' . $k . '\'], \'' . $_dictCode . '\');' . PHP_EOL;
                    $foreachBindQuery .= '        $query[\'' . $k . '_res\'] = DataComponent::getDictData($query[\'' . $k . '\'], \'' . $_dictCode . '\');' . PHP_EOL;

                } else {
                    $userArray[] = 'use application\\component\\DataComponent;' . PHP_EOL;
                    $foreachBind .= '            $rows[$k][\'' . $k . '_res\'] = DataComponent::getDbField($v[\'' . $k . '\'], $' . $_smallTableName . 'Res);' . PHP_EOL;
                    $foreachBindQuery .= '        $query[\'' . $k . '_res\'] = DataComponent::getDbField($query[\'' . $k . '\'], $' . $_smallTableName . 'Res);' . PHP_EOL;


                }
            }
            $foreachBind .= '        }' . PHP_EOL;
        }

        $serviceImpl = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $serviceImpl);
        $serviceImpl = str_replace('{$Name}', $bigTableName, $serviceImpl);
        $serviceImpl = str_replace('{$prefix}', $prefix, $serviceImpl);
        $userArray = array_unique($userArray);
        $useStr = "";
        if (!empty($userArray)) {
            $useStr = implode("", $userArray);
        }
        $businessCode = implode(PHP_EOL, $keysArray) . PHP_EOL;
        $businessCode .= $foreachMapping;
        $businessCode .= $mappingRes;
        $businessCode .= $dictDataRes;
        $businessCode .= $catalogRes;
        $businessCode .= $foreachBind;
        $businessCodeQuery = $mappingResQuery;
        $businessCodeQuery.=$foreachBindQuery;
        /////////a$foreachBindQuery
        if (!empty(trim($businessCode))) {
            $businessCode = '        $rows = $lists[\'rows\'] ?? $lists;' . PHP_EOL . '        //首先判断是否有数据，如果没有数据则直接返回' . PHP_EOL . '        if (empty($rows)) {' . PHP_EOL . '            return $lists;' . PHP_EOL . '        } ' . PHP_EOL . $businessCode . PHP_EOL . '        isset($lists[\'rows\']) ? ($lists[\'rows\'] = $rows) : ($lists = $rows);';
            $serviceImpl = str_replace('{$businessCode}', $businessCode, $serviceImpl);
            $serviceImpl = str_replace('{$businessCodeQuery}', $businessCodeQuery, $serviceImpl);

        } else {
            $serviceImpl = str_replace('{$businessCode}', "", $serviceImpl);
            $serviceImpl = str_replace('{$businessCodeQuery}', "", $serviceImpl);

        }
        $serviceImpl = str_replace('{$use}', $useStr, $serviceImpl);

        $mapper = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $mapper);
        $mapper = str_replace('{$Name}', $bigTableName, $mapper);
        $mapper = str_replace('{$table_name}', $tableName, $mapper);
        $mapper = str_replace('{$prefix}', $prefix, $mapper);

        $xml = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $xml);
        $xml = str_replace('{$tableRemarks}', $tableRemarks, $xml);
        $xml = str_replace('{$table_name}', $tableName, $xml);
        $xml = str_replace('{$fields}', $fields, $xml);
        $xml = str_replace('{$selectFields}', $selectFields, $xml);

        $xml = str_replace('{$fieldsBindValue}', $fieldsBindValue, $xml);
        $xml = str_replace('{$fieldSet}', $fieldSet, $xml);
        $xml = str_replace('{$searchWhere}', $searchWhere, $xml);

        if ($indexSearchForm != "") {
            $indexSearchForm .= '                <div class="layui-inline">' . PHP_EOL;
            $indexSearchForm .= '                    <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn">搜 索</button>' . PHP_EOL;
            $indexSearchForm .= '                </div>' . PHP_EOL;
        }
        $cols = implode("," . PHP_EOL, $colsArray);
        $cols = '[' . PHP_EOL . $cols . PHP_EOL . '            ]';
        $index = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $index);
        $index = str_replace('{$indexSearchForm}', $indexSearchForm, $index);
        $index = str_replace('{$indexInitDictData}', $indexInitDictData, $index);
        $index = str_replace('{$indexInitDbTableData}', $indexInitDbTableData, $index);
        $index = str_replace('{$indexInitTreeParentData}', $indexInitTreeParentData, $index);
        $index = str_replace('{$cols}', $cols, $index);
        if (file_exists($customJsPath)) {
            $index = str_replace('{$custom.js}', '<script src="./custom.js"></script>', $index);
            if (strpos(file_get_contents($customJsPath), 'toolbarTapCustom') !== false) {
                $index = str_replace('{$toolbarTapCustom(data,pars,event)};', 'toolbarTapCustom(data,pars,event);', $index);
            } else {
                $index = str_replace('{$toolbarTapCustom(data,pars,event)};', '', $index);
            }
        } else {
            $index = str_replace('{$custom.js}', '', $index);
            $index = str_replace('{$toolbarTapCustom(data,pars,event)};', '', $index);
        }
        $add = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $add);
        $add = str_replace('{$addForm}', $addForm, $add);
        $add = str_replace('{$addInitDictData}', $addInitDictData, $add);
        $add = str_replace('{$addInitDbTableData}', $addInitDbTableData, $add);
        $add = str_replace('{$addInitTreeParentData}', $addInitTreeParentData, $add);
        $add = str_replace('{$wangEditorJs}', $wangEditorJs, $add);
        $add = str_replace('{$initEditor}', $initEditor, $add);
        if (file_exists($customJsPath)) {
            $add = str_replace('{$custom.js}', '<script src="./custom.js"></script>', $add);
        } else {
            $add = str_replace('{$custom.js}', '', $add);
        }

        $edit = str_replace('{$generationTime}', date("Y-m-d H:i:s"), $edit);
        $edit = str_replace('{$editForm}', $editForm, $edit);
        $edit = str_replace('{$editInitDictData}', $editInitDictData, $edit);
        $edit = str_replace('{$editInitDbTableData}', $editInitDbTableData, $edit);
        $edit = str_replace('{$editInitTreeParentData}', $editInitTreeParentData, $edit);
        $edit = str_replace('{$wangEditorJs}', $wangEditorJs, $edit);
        $edit = str_replace('{$initEditor}', $initEditor, $edit);
        if (file_exists($customJsPath)) {
            $edit = str_replace('{$custom.js}', '<script src="./custom.js"></script>', $edit);
        } else {
            $edit = str_replace('{$custom.js}', '', $edit);
        }

        return [
            'prefix' => $prefix,
            'filter' => $filter,
            'html_dir' => $smallTableName,
            'class_name' => $bigTableName,
            'controller' => $controller,
            'service' => $service,
            'service_impl' => $serviceImpl,
            'mapper' => $mapper,
            'xml' => $xml,
            'index' => $index,
            'add' => $add,
            'edit' => $edit,
        ];

    }
}